#include "vxlabel.h"

VxLabel::VxLabel(VxLabelData * data, QWidget * parent) :
		QWidget::QWidget(parent)
{
	QHBoxLayout * layout = new QHBoxLayout();
	setLayout(layout);

	_label = new QLabel();
	_label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored);
	_info = new QLabel();
	layout->addWidget(_label);
	layout->addWidget(_info);

	_label->setObjectName("vxLabelLabel");
	_info->setObjectName("vxLabelInfo");
	_label->setProperty("_hover", false);

	_label->installEventFilter(this);
	_label->setMouseTracking(true);
	_label->setLayoutDirection(Qt::RightToLeft);

	_label->setCursor(Qt::PointingHandCursor);

	setData(data);

}


void VxLabel::setData(VxLabelData * data)
{
	_data = data;
	_label->setText(QString(":%1").arg(_data->getCaption()));
	_info->setText(_data->getData().toString());
}



bool VxLabel::eventFilter(QObject * obj, QEvent * event)
{
	switch(event->type()){

	case QEvent::Enter: {
			_label->setProperty("_hover", true);
			_label->setStyleSheet(qApp->styleSheet());
			break;
		}

	case QEvent::Leave: {
			_label->setProperty("_hover", false);
			_label->setStyleSheet(qApp->styleSheet());
			break;
		}

	default:;

	}

	return QWidget::eventFilter(obj, event);
}



void VxLabel::showLabel()
{
	parentWidget()->layout()->removeWidget(this);
	parentWidget()->layout()->addWidget(this);
	show();
}
